﻿using Ace.Application;
using Ace.Data;
using Ace.Entity.Wiki;
using Ace.Exceptions;
using Ace.IdStrategy;
using Chloe;
using Chloe.MySql;
using Chloe.SqlServer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ace.Application.Wiki
{
    public interface IALogService : IAppService
    {

        void AddLog(string Title, string LogContent, string Result);
        

        void Delete(int Id );


        PagedData<ALog> GetPageData(Pagination page);
    }

    public class ALogService : AppServiceBase<ALog>, IALogService
    {
        public ALogService(IDbContext dbContext, IServiceProvider services) : base(dbContext, services)
        {
        }


        public void AddLog(string Title, string LogContent,string Result)
        {
            if (!string.IsNullOrEmpty(Title) && !string.IsNullOrEmpty(LogContent))
            {
                string sql = "insert into alog(Title,LogContent,Result,AddDate)values('" + Title + "','" + LogContent + "','" + Result + "',now());";
                this.DbContext.Session.ExecuteNonQuery(sql);
            }
        }

      

       

        public void Delete(int Id)
        {
            this.DbContext.Session.ExecuteNonQuery("delete from alog where Id=" + Id);
        }


        public PagedData<ALog> GetPageData(Pagination page)
        {
            var q = this.DbContext.Query<ALog>();
            q = q.OrderByDesc(a => a.AddDate);
            
            PagedData<ALog> pagedData = q.TakePageData(page);
            return pagedData;
        }

         

    }

}
